package com.dongdongshop.log;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
//@Aspect//声明是一个切面类Aop;面向切面编程
public class LogAspect {
//    private Logger logger = LoggerFactory.getLogger(LogAspect.class);
//    @Pointcut("execution(public * com.dongdongshop.service.*.*(..))")
//    public void aopLog() {
//    }
//
//    @Before("aopLog()")
//    public void deBefore(JoinPoint joinPoint) {
////        打印进入哪个方法,参数是什么
////        获取参数,因为参数类型,个数不确定,所以使用Object[];来接受
//        Object[] args = joinPoint.getArgs();
//        //获取方法
//        Signature signature = joinPoint.getSignature();
//        logger.info("进入方法: {}, 参数为: {}", signature , args);
//    }
//    @AfterReturning(pointcut="aopLog()",returning ="obj" )
//
//    public void doAfterReturning(Object obj)throws Throwable{
////打印返回值
//        logger.info("方法执行成功,返回值为: {}", JSONObject.toJSONString(obj));
//    }
}
